package com.hex.ds.hdtp.core.app.data.transfer.converter;

import cn.hutool.core.date.DateUtil;
import com.hex.ds.hdtp.core.app.data.transfer.dto.request.DataTransferDownwardNumDto;
import com.hex.ds.hdtp.core.app.data.transfer.dto.request.DataTransferLogRequestDto;
import com.hex.ds.hdtp.core.app.data.transfer.dto.response.DataTransferListResponseDto;
import com.hex.ds.hdtp.core.app.data.transfer.dto.response.DataTransferLogResponseDto;
import com.hex.ds.hdtp.core.app.data.transfer.entry.DownNumInfo;
import com.hex.ds.hdtp.core.inf.data.transfer.po.DataTransferLogPo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Package: com.hex.ds.hdtp.core.app.data.transfer.converter
 * @ClassName IDataTransferLogConverter
 * @Description: 数据迁移记录-PO对象转DTO对象
 * @Author: wz.li
 * @Date 2023/8/18 13:46
 * @Version v2.0.2
 **/
@Service
@Mapper(componentModel = "spring", imports = {DateUtil.class})
public interface IDataTransferLogConverter {

    DataTransferLogPo toPo(DataTransferLogRequestDto dataTransferLogRequestDto);

    List<DataTransferLogResponseDto> toDtoList(List<DataTransferLogPo> dataTransferLogPos);

    @Mapping(target = "pkId", ignore = true)
    @Mapping(target = "dataTransferListPkId", source = "dataTransferListResponseDto.pkId")
    @Mapping(target = "bizDate", source = "bizDate")
    @Mapping(target = "status", constant = "RUNNING")
    @Mapping(target = "startTime", expression = "java(DateUtil.now())")
    @Mapping(target = "analysisResult", source = "dataAnalysisResult")
    DataTransferLogRequestDto toDto(DataTransferListResponseDto dataTransferListResponseDto, String bizDate, String dataAnalysisResult);




    @Mapping(target = "dataTransferTaskPkId",source = "dataTransferDownwardNumDto.taskId")
    @Mapping(target = "dataTransferListPkId",source = "downNumInfo.pkId")
    @Mapping(target = "sourceConnPkId",source = "dataTransferDownwardNumDto.sourceConnId")
    @Mapping(target = "sourceDatabaseName",source = "downNumInfo.sourceDatabaseName")
    @Mapping(target = "sourceTableName",source = "downNumInfo.sourceTableName")
    @Mapping(target = "exportDataFileResult",source = "downNumInfo.exportDataFileResult")
    @Mapping(target = "pkId", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_DEFAULT)
    DataTransferLogRequestDto toDownNumDto(DataTransferDownwardNumDto dataTransferDownwardNumDto, DownNumInfo downNumInfo);

}
